/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code1 {
    int ret = 0;
    int _k = 0;
    public int kthSmallest(TreeNode root, int k) {
        _k = k;
        dfs(root);
        return ret;
    }

    public void dfs(TreeNode root) {
        //出口
        if(root ==  null) {
            return;
        }

        dfs(root.left);
        if(--_k == 0) {
            ret = root.val;
        }
        dfs(root.right);
    }
}